/*
 * @Author: FanWeiHua
 * @Date: 2021-07-08 10:44:21
 * @LastEditTime: 2021-07-20 17:46:18
 * @Description: 首页
 */
'use strict';
import React, { useEffect } from 'react';
import { useHistory } from 'react-router';
import { DatePicker } from 'antd';
import { store } from '@/common/store/store';
import { FormattedMessage } from 'react-intl';
import './index.less';
import { getName, modifyName } from '../../services/global';
/**
 * 主题切换demo
 */
let className = 'theme-sky';
setInterval(() => {
  if (className === 'theme-sky') {
    className = 'theme-red';
    store.dispatch({
      type: 'global/setLocale',
      payload: { locale: 'en' }
    });
  } else {
    className = 'theme-sky';
    store.dispatch({
      type: 'global/setLocale',
      payload: { locale: 'zh' }
    });
  }
  document.getElementById('root').setAttribute('class', className);
}, 2000);
/**
 * 入口
 */
const Index = () => {
  const history = useHistory();
  useEffect(() => {
    getName().then(result => {
      console.log(result);
    });
    modifyName().then(result => {
      console.log(result);
    });
    return () => {
      console.log('组件卸载');
    };
  }, []);
  const onHEvent = () => {
    history.push('/handle');
  };
  return (
    <main className="index">
      <div className="universe animate__animated animate__fadeIn" />
      <DatePicker />
      <h1 className="animate__animated animate__fadeIn m-title" onClick={() => onHEvent()}>
        <FormattedMessage id="app.title" defaultMessage="欢迎加入前端组，你的一言一行都在影响着他人" />
      </h1>
    </main>
  );
};
export default Index;
